﻿@page "/docs/type/{type}"
@using Gentings.Documents.XmlDocuments
@model TypeModel

<div class="docs-wrapper flex-column p-3" style="margin-top:-1rem;">
    <div class="d-flex align-items-center p-3 mb-3 text-white-50 bg-primary rounded shadow-sm">
        <div class="icon-48 text-uppercase">@Model.TagName</div>
        <div class="px-3" style="flex:auto;">
            <h2 class="mb-0 text-white">@ViewBag.Title</h2>
            <small>@Model.TypeDescriptor!.Summary</small>
        </div>
        <a href="#" onclick="history.go(-1);return false;" title="返回" style="font-size:2rem;color:var(--bs-light);" .icon="bi-reply"></a>
    </div>

    <div class="card">
        <div class="card-body">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>属性名称</th>
                        @if (Model.Type!.IsEnum)
                        {
                        <th>值</th>
                        }
                        else
                        {
                        <th>类型</th>
                        }
                        <th>描述</th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model.Type.IsEnum)
                    {
                        foreach (var value in Enum.GetValues(Model.Type))
                        {
                            var descriptor = Model.TypeDescriptor.GetPropertyDescriptor(value.ToString());
                            <tr>
                                <td>@value</td>
                                <td>
                                    @($"{value:d}")
                                </td>
                                <td>
                                    @descriptor.Summary
                                </td>
                            </tr>
                        }
                    }
                    else
                    {
                        foreach (var property in Model.Type.GetProperties())
                        {
                            if (!property.CanRead || !property.CanWrite)
                            {
                                continue;
                            }
                            var descriptor = Model.TypeDescriptor.GetPropertyDescriptor(property.Name);
                            if (descriptor == null)
                            {
                                continue;
                            }
                            var propertyType = property.PropertyType;
                            <tr>
                                <td>@property.Name</td>
                                <td>
                                    @if (propertyType.IsLinkable())
                                    {
                                        <a asp-route-type="@propertyType.FullName">@propertyType.GetRealTypeName()</a>
                                    }
                                    else
                                    {
                                        <span>@propertyType.GetRealTypeName()</span>
                                    }
                                </td>
                                <td>
                                    @descriptor.Summary
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
            <ul class="nav nav-tabs bordered" role="tablist">
                <li class="nav-item active">
                    <a class="nav-link active" id="cs-tab" data-bs-toggle="tab" href="#cs" role="tab">C#</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" id="ts-tab" data-bs-toggle="tab" href="#ts" role="tab">TypeScript</a>
                </li>
            </ul>
            <div class="tab-content pb-2">
                <div id="cs" class="media text-muted pt-3 tab-pane fade show active">
                    <pre><code class="language-csharp p-0">@Model.Type.GetClass()</code></pre>
                </div>
                <div id="ts" class="media text-muted pt-3 tab-pane fade">
                    <pre><code class="language-typescript p-0">@Model.Type.GetTypeScriptInterface()</code></pre>
                </div>
            </div>
        </div>
    </div>
</div>